<?php

namespace App\Service;

use Phalcon\Di;
use App\Util\Fun;

class BaseService
{
	
	public static function getDi()
    {
        return Di::getDefault();
    }
	
	public static function echoJson($data,$code){
		return (new Fun)->echoJson($data,(int)$code);
	}

	/**
	 * [orderBy 排序参数]
	 * @param  [type] $orderBy [description]
	 * @return [type]          [description]
	 */
	public static function orderBy($orderBy, $table = NULL)
	{
		$sql = NULL;
		$table = $table ? " " . $table . "." : " ";
		
		if (isset($orderBy) && is_object($orderBy) && count((array)$orderBy) > 0){
			foreach ($orderBy as $key => $value) {
				switch ($value) {
					case -1:
						$sql .= $table . $key . " DESC ";
						break;
					case 1:
						$sql .= $table . $key . " ASC ";
						break;
					default:
						$sql = NULL;
						break;
				}
				$sql .= ',';
			}
			$sql = substr($sql,0,-1);
		}
		$sql = $sql ? $sql : $table . "create_time DESC";
		
		return $sql;
	} 
}